﻿using System;
using System.Linq;
using System.Windows.Forms;

namespace Project.Co_DataTransformationPrototype.UI
{
    public partial class MoveDialogBox : Form
    {
        private EntityShape[] entityArray;
        private EntityAttribute[] attributeArray;
        public Entity targetEntity;

        public MoveDialogBox(EntityShape[] entityArray, EntityAttribute[] attributeArray)
        {
            this.entityArray = entityArray;
            this.attributeArray = attributeArray;
            InitializeComponent();
        }

        private void MoveDialogBox_Load(object sender, EventArgs e)
        {
            cboEntities.Items.AddRange(entityArray.Select<EntityShape, Entity>(s => (s.ModelElement as Entity)).OrderBy(ent => ent.CurrentName).ToArray());
            if (attributeArray != null && attributeArray.Length > 0)
                lstbAttributes.Items.AddRange(attributeArray);           
        }

        private void btnSelect_Click(object sender, EventArgs e)
        {
            if (cboEntities.SelectedItem != null)
            {
                targetEntity = cboEntities.SelectedItem as Entity;
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
        }

    }
}
